'use strict'

angular.module('myApp.viewAddNewTask', ['ngRoute'])

    .controller('ViewAddNewTask', ['$rootScope', '$scope', '$routeParams', '$location', function ($rootScope, $scope, $routeParams, $location) {
        $scope.taskId;
        $scope.taskContent;

        $scope.onCommitNewTask = function () {
            var date = new Date();
            var creationTime = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + ' '
                + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();

            var newTask = {
                "task_id": $rootScope.taskIdSeed++,
                "task_content": $scope.taskContent,
                "creation_time": creationTime
            };
            $rootScope.tasks.push(newTask);

            $location.path('/' + $scope.userName + '/tasklist');
        };
    }]);